package cn.edu.hbcit.text1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataBaseConnect {
    /**
     * 获得数据库连接
     *
     * @return conn
     */
    public static Connection getCoon() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("加载驱动成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("驱动加载失败");
        }
        String url = "jdbc:mysql://localhost:3306/text";
        String username = "root";
        String password = "123456";
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, username, password);
            System.out.println("连接对象获取成功");
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("连接对象获取失败");
        }
        return conn;
    }
}
